package com.app.mymusic.ui;


import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.app.mymusic.R;
import com.app.mymusic.adapter.DownloadOverAdapter;
import com.app.mymusic.model.Mp3Info;
import com.app.mymusic.model.Mp3InfoDao;
import com.app.mymusic.utils.LogUtil;
import com.app.mymusic.widget.PopWindowMenu;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/8/8.
 */
public class DownLoadOverFragment extends Fragment {
    @BindView(R.id.over_recycler)
    RecyclerView mRecyclerView;
    private Mp3InfoDao mp3Dao;
    private DownloadOverAdapter mAdapter;
    private List<Mp3Info> mDatas=new ArrayList<Mp3Info>();

    public DownLoadOverFragment() {
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mp3Dao=new Mp3InfoDao(getActivity());
        mDatas.clear();
        mDatas.addAll(mp3Dao.getAll());

    }

    View view;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         view = inflater.inflate(R.layout.downloadoverfragment, container, false);
        ButterKnife.bind(this, view);
        mAdapter=new DownloadOverAdapter(R.layout.item_downloadoverfragment,mDatas);
        LinearLayoutManager manager=new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(manager);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.addOnItemTouchListener(new ItemChildListener());
        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtil.showLog("o--ondestroy");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onResume() {
        super.onResume();
        LogUtil.showLog("o--onResume");
    }
    @Override
    public void onStart() {
        super.onStart();
        LogUtil.showLog("o--onStart");
    }

    private class ItemChildListener extends OnItemClickListener{
        @Override
        public void onSimpleItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
            PopWindowMenu pw=new PopWindowMenu(mDatas.get(i));
            pw.getPopWindow(getActivity()).showAtLocation(view.getRootView(),Gravity.BOTTOM,0,0);
        }
    }
}
